﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DevExpress.Xpo;
using DevExpress.XtraEditors;
using NetworkSupervisor.Model.NetworkSupervisor;

namespace NetworkSupervisor
{
    public partial class FormQQZoneViewer : DevExpress.XtraEditors.XtraForm
    {
        private bool closeIt = false;

        public FormQQZoneViewer()
        {
            InitializeComponent();
        }

        private FormLoadProgress loading = null;

        private void FormQQZoneViewer_Shown(object sender, EventArgs e)
        {
            loading = new FormLoadProgress();
            loading.mySetInfo("正在加载数据，请等候...");
            loading.mySetProgressMaximum(XPCQQ列表.Count);
            this.BeginInvoke(new MethodInvoker(() => loading.ShowDialog()));
            System.Threading.ThreadPool.QueueUserWorkItem(initOnlineCountAndLastOnLineTime);
        }

        private void initOnlineCountAndLastOnLineTime(object state)
        {
            List<taQQ列表> list = XPCQQ列表.Cast<taQQ列表>().ToList();
            int i = 0;
            foreach (taQQ列表 item in list)
            {
                if (closeIt) return;
                try
                {
                    this.UIThread(() => item.Set在线次数());
                    this.UIThread(() => loading.mySetProgressPosition(++i));
                }
                catch
                {
                }
            }
            this.UIThread(() => loading.myClose());
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
        }

        private void btnKJZC_Click(object sender, EventArgs e)
        {
            string text = "空间正常";
            UpdateJianChaQWingKuang(text);
        }

        private void btnJMKJ_Click(object sender, EventArgs e)
        {
            string text = "加密空间";
            UpdateJianChaQWingKuang(text);
        }

        private void btnXLSF_Click(object sender, EventArgs e)
        {
            string text = "泄露身份";
            UpdateJianChaQWingKuang(text);
        }

        private void UpdateJianChaQWingKuang(string text)
        {
            gridView1.SetFocusedRowCellValue("空间检查情况", text);
            gridView1.SetFocusedRowCellValue("上次检查时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            gridView1.Focus();
            btnCustom.Focus();
            gridView1.Focus();
        }

        private void btnSWKT_Click(object sender, EventArgs e)
        {
            UpdateJianChaQWingKuang("尚未开通");
        }

        private void btnCustom_Click(object sender, EventArgs e)
        {
            string text = memoEdit1.Text;
            if (text == "")
            {
                XtraMessageBox.Show("请输入自定义信息");
                memoEdit1.Focus();
                return;
            }
            UpdateJianChaQWingKuang(text);
        }

        private void btnPrev_Click(object sender, EventArgs e)
        {
            gridView1.MovePrev();
            gridView1_DoubleClick(null, null);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            gridView1.MoveNext();
            gridView1_DoubleClick(null, null);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (gridView1.RowCount < 1) return;

            taQQ列表 item = gridView1.GetFocusedRow() as Model.NetworkSupervisor.taQQ列表;
            string url = string.Format("http://{0}.qzone.qq.com/", item.QQ);
            string groupTitle = string.Format("当前QQ是：{0}", item.QQ);
            groupControl2.Text = groupTitle;
            webBrowser1.Navigate(url);
        }

        private void FormQQZoneViewer_Load(object sender, EventArgs e)
        {
        }

        private void FormQQZoneViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            closeIt = true;
        }
    }
}